package com.yanqu.road.dataHelper.action.excel;

import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.ConfigMgr;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.repair.BaseRepair;
import com.yanqu.road.entity.player.UserInfo;

import java.math.BigInteger;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author xx
 * @Date 2020/11/11
 */
public class HsgBuy extends BaseRepair {

    public HsgBuy(GameServer gameServer) {
        super(gameServer);
    }

    @Override
    public void repair(long param1, String param2) {

    }

    public void go(){
        List<Map<String, String>> listMap = new ArrayList<>();
        listMap = getLogBuy("2020-11-09","2020-11-13");
        DataMgr.addData(listMap);
    }

    private List<Map<String, String>> getLogBuy(String start,String end) {
        List<Map<String, String>> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * " +
                " from t_l_buy " +
                " where shopType = 12 AND `time` > ? AND `time` < ?";
        try {
            call = getGameServer().getLogConnection().prepareCall(sql);
            int i=1;
            call.setString(i++,start);
            call.setString(i++,end);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String,String> temp = new ConcurrentHashMap<>();
                temp.put("serverId",String.valueOf(getGameServer().getServerInfo().getServerId()));
                temp.put("userId",checkNullToEmpty(rs.getString("userId")));
                temp.put("mallId",checkNullToEmpty(rs.getString("mallId")));
                temp.put("商品名称", ConfigMgr.getMallName(Integer.valueOf(rs.getString("mallId"))));
                temp.put("count",checkNullToEmpty(rs.getString("count")));
                temp.put("time",checkNullToEmpty(rs.getString("time")));
                temp.put("price",checkNullToEmpty(rs.getString("price")));
                temp.put("shopType",checkNullToEmpty(rs.getString("shopType")));
                temp.put("goods",checkNullToEmpty(rs.getString("goods")));
                UserInfo userInfo = getUserInfo(temp.get("userId"));
                temp.put("vipExp",String.valueOf(userInfo.getVipExp()));

                dataList.add(temp);
            }
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return dataList;
    }
}
